package com.gexiaobao.pigeon.ui.adapter

import android.widget.ImageView
import androidx.appcompat.widget.AppCompatImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.flyjingfish.openimagelib.OpenImage
import com.flyjingfish.openimagelib.enums.MediaType
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.BloodBookListBean
import com.gexiaobao.pigeon.app.util.ImageLoaderManager
import com.gexiaobao.pigeon.databinding.ItemMakePedigreeBookBinding

/**
 * @Author      : hxw
 * @Date        : 2024/9/13 8:28
 * @Describe    :
 */
class AdapterMakePedigreeBooks : BaseQuickAdapter<BloodBookListBean, DataBindBaseViewHolder>(R.layout.item_make_pedigree_book) {
    override fun convert(holder: DataBindBaseViewHolder, item: BloodBookListBean) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemMakePedigreeBookBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        val ivMalePedigreeBooksImage = holder.getView<AppCompatImageView>(R.id.ivMalePedigreeBooksImage)
        ImageLoaderManager.loadRoundImage(context, item.pgImg, ivMalePedigreeBooksImage, 8)

        ivMalePedigreeBooksImage.setOnClickListener {
            if (item.pgImg.isNotEmpty()) {
                OpenImage.with(context)
                    .setClickImageView(ivMalePedigreeBooksImage)
                    .setSrcImageViewScaleType(ImageView.ScaleType.CENTER_CROP, true)
                    .setImageUrl(item.pgImg, MediaType.IMAGE).show()
            }
        }

        val sexImage: Int = if (item.sex == "雌") {
            R.mipmap.icon_female
        } else {
            R.mipmap.icon_male
        }
        holder.setImageResource(R.id.ivMakePedigreeBooksSex, sexImage)
    }
}